<template>
  <div class="length_item" :style="[rowShowCountCpd]">
    <div class="left">
      <img :src="item.picUrl" />
      <span class="iconfont play_icon icon-kaishi1"></span>
    </div>
    <div class="right">
      <div class="title_sub">
        <p class="music_name">{{ item.name }}</p>
        <p class="auth_name">{{ item.song.artists[0].name }}</p>
      </div>
      <div class="options">
        <span class="iconfont icon-aixin"></span>
        <span class="iconfont icon-kaishi1"></span>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { PropType, computed, onMounted, ref } from 'vue'

defineProps({
  item: {
    type: Object as PropType<any>,
    default: () => {
      return {}
    }
  }
})

// 根据窗口大小动态调整每行显示的个数
const rowShowCount = ref(2)
const rowShowCountCpd = computed(() => {
  if (rowShowCount.value === 2) {
    return ` width: 48%;`
  } else {
    return ` width: 30%`
  }
})

// 监听主进程传递的窗口大小信息
const windowSize = () => {
  window.electron.ipcRenderer.on('window-resized', (_, { width }) => {
    if (width > 1200) {
      rowShowCount.value = 3
    } else {
      rowShowCount.value = 2
    }
  })
}

onMounted(() => {
  windowSize()
})
</script>

<style scoped lang="scss">
.length_item {
  width: 48%;
  padding: 10px;
  box-sizing: border-box;
  display: flex;
  cursor: pointer;

  .left {
    position: relative;
    img {
      width: 80px;
      height: 80px;
      border-radius: 5px;
    }
    .play_icon {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      font-size: 30px;
      color: #fff;
      opacity: 0;
      transition: all 0.3s;
    }
    &:hover .play_icon {
      opacity: 1;
    }
  }

  .right {
    flex: 1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .title_sub {
      display: flex;
      flex-direction: column;
      justify-content: center;
      margin-left: 10px;

      .music_name {
        /* 多行文本省略 */
        display: -webkit-box;
        -webkit-line-clamp: 1;
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: 16px;
      }
      .auth_name {
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: 16px;
      }
    }
    .options {
      opacity: 0;
      padding-right: 15px;
      transition: all 0.3s;
      & span:first-child {
        margin-right: 10px;
      }
      span {
        font-size: 20px;
        color: #999;
      }
      span:hover {
        color: #fff;
      }
    }
  }

  &:hover {
    background-color: var(--ev-main-bgc);
  }
  &:hover .options {
    opacity: 1;
  }
  &:hover .left .play_icon {
    opacity: 1;
  }
}
</style>
